/**
 * 
 */
package com.xiaomuedu.controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.xiaomuedu.model.User;

/**
 * @author acer
 *
 */
public class UserController extends Controller {

	public void index(){
		List<User> users = User.dao.find("select * from user");
		setAttr("users", users);
 		render("list.jsp");
	}
	
	public void form(){
		Integer id = getParaToInt(0);
		if(id!=null && id>0)
		{
			setAttr("user", User.dao.findById(id));
		}
		render("form.jsp");
	}
	
	public void submit()
	{
		User user = getModel(User.class,"user");
		user.save();
		redirect("/user");
	}
	
	public void update()
	{
		User user = getModel(User.class,"user");
		user.update();
		redirect("/user");
	}
	
	public void edit()
	{
		
		form();
	}
	
	public void del()
	{
		User.dao.deleteById(getPara(0));
		redirect("/user");
	}
}
